/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package vzone.tools;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;

/**
 *
 * @author Kingpro
 */
public class sqlConfig
{

    private static sqlConfig config = new sqlConfig();

    public static sqlConfig getSqlConfig()
    {
	return config;
    }
    public String server = "localhost";
    public int port = 1433;
    public String user = "sa";
    public String pwd = "lavender";
    public String database = "vzone";

    public sqlConfig()
    {
	try
	{
	    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
	    DocumentBuilder dbd = dbf.newDocumentBuilder();
	    Document doc = dbd.parse(new FileInputStream(new File("Sql.config.xml").getAbsolutePath()));

	    XPathFactory f = XPathFactory.newInstance();
	    XPath path = f.newXPath();
	    server= ((Node)path.evaluate("sql/server", doc, XPathConstants.NODE)).getTextContent();
	    port= Integer.parseInt(((Node)path.evaluate("sql/port", doc, XPathConstants.NODE)).getTextContent());
	    user= ((Node)path.evaluate("sql/username", doc, XPathConstants.NODE)).getTextContent();
	    pwd= ((Node)path.evaluate("sql/password", doc, XPathConstants.NODE)).getTextContent();
	    database= ((Node)path.evaluate("sql/database", doc, XPathConstants.NODE)).getTextContent();
	}
	catch (XPathExpressionException ex)
	{
	    Logger.getLogger(sqlConfig.class.getName()).log(Level.SEVERE, null, ex);
	}
	catch (SAXException ex)
	{
	    Logger.getLogger(sqlConfig.class.getName()).log(Level.SEVERE, null, ex);
	}
	catch (IOException ex)
	{
	    Logger.getLogger(sqlConfig.class.getName()).log(Level.SEVERE, null, ex);
	}
	catch (ParserConfigurationException ex)
	{
	    Logger.getLogger(sqlConfig.class.getName()).log(Level.SEVERE, null, ex);
	}
    }
}
